package com.cee.admin.modules.prod.general.controller;

import com.cee.admin.common.BaseController;
import com.cee.common.validator.constraints.ValidationGroups;
import com.cee.common.web.result.Result;
import com.cee.domain.constants.DomainConstants;
import com.cee.domain.modules.prod.general.form.ProdProductGeneralFillForm;
import com.cee.ds.modules.prod.general.service.IProdGeneralService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


/**
 * @author wsz
 * @since 2024/7/8
 */
@Tag(name = "产品管理-产品-通用行业产品数据填报基本信息")
@RestController
@RequestMapping("/api/prod/product/general/base")
public class ProdProductGeneralBaseController extends BaseController {

    @Autowired
    private IProdGeneralService generalService;

    @Operation(summary = "保存数据填报")
    @PostMapping("/save")
    public Result<Long> save(@RequestBody @Validated(ValidationGroups.SaveDraft.class) ProdProductGeneralFillForm form) {
        return success(generalService.upsert(form, DomainConstants.COMMON_UNSUBMITTED_AUDIT_STATUS));
    }

    @Operation(summary = "提交数据填报")
    @PostMapping("/submit")
    public Result<Boolean> submit(@RequestBody @Validated(ValidationGroups.Submit.class) ProdProductGeneralFillForm form) {
        return success(generalService.upsert(form, DomainConstants.COMMON_UNAUDITED_STATUS) != null);
    }
    @Operation(summary = "查看数据填报详情")
    @GetMapping("/get/{id}")
    public Result<ProdProductGeneralFillForm> get(@PathVariable("id") @Parameter(description = "数据填报id")Long id){
        return success(generalService.getForm(id));
    }

    @Operation(summary = "删除数据填报")
    @DeleteMapping("/delete/{id}")
    public Result<Boolean> delete(@PathVariable("id")@Parameter(description = "数据填报id") Long id){
        return success(generalService.removeByDataReportId(id));
    }

}
